﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using QASPRibbon.Extensions;
using Schema = QASPRibbon.RibbonSchema;

namespace QASPRibbon.Controls
{
    /// <summary>
    /// 
    /// </summary>
    public class RibbonStrip : RibbonControl
    {
        internal override string XmlTag
        {
            get { return Schema.Strip; }
        }

        internal override XElement AsXElement()
        {
            return new XElement(XmlTag);
        }

        public IEnumerable<RibbonControl> Controls { get; set; }

        public RibbonDisplayMode DisplayMode
        {
            get { return _displayMode; }
            set { _displayMode = value; }
        }

        internal IEnumerable<RibbonControl> AllControls
        {
            get
            {
                var res = new List<RibbonControl>();
                foreach (var control in Controls.Where(c => c.Visible))
                {
                    if (control is IRibbonContainer<RibbonControl>)
                    {
                        var container = control is IRibbonMenu
                                            ? ((IRibbonMenu)control)
                                            : ((IRibbonContainer<RibbonControl>)control);
                        res.Add(control);
                        res.AddRange(container.AllControls());
                    }
                    else
                    {
                        res.Add(control);
                    }
                }
                return res;
            }
        }

        private RibbonDisplayMode _displayMode = RibbonDisplayMode.Image32AndCaption;
    }
}
